<template>
	<rich-text :nodes="strHtml" @itemclick="handleRich"></rich-text>
</template>
 
<script setup>
	//定义测试的html字符串
	let strHtml = `
		<div><p>一般完成Java的基础语法和JavaSe部分已经Spring boot框架后，就可以开始工作，在工作中不断实践拓展提高自己的技术能力</p><img  src="https://img0.baidu.com/it/u=265713382,944125301&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=889" width="300" height="300" /></div>
	`;
	//处理点击事件
	const handleRich = (e)=>{
		// console.log(e.detail.node.attrs.src,e);
		let imgPath = e.detail.node.attrs.src;
		handlePreViewImage(imgPath);
	}
	//预览和长按保存图片
	const handlePreViewImage = (imgPath)=>{
		let arr = [];
		arr.push(imgPath);
		uni.previewImage({
			urls: arr,
			longPressActions: {
				itemList: ['保存图片到相册'],
				success: function(data) {
					console.log(data.tapIndex);
					if(data.tapIndex == 0){
						uni.saveImageToPhotosAlbum({
							filePath: imgPath,
							success: function () {
								uni.showToast({
									title: '保存成功',
									duration: 2000
								});
							}
						});
					}
				},
				fail: function(err) {
					console.log(err.errMsg);
				}
			}
		});
	}
	
</script>
 
<style scoped lang="scss">
</style>